//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include "aura.h"
#include "wince.h"
#include "private.h"

AURA_API AuraTls_Allocate(
    /* [out] */ Aura_UInt32 * pIndex)
{
    DWORD dwTlsIndex;

    assert(NULL != pIndex);

    dwTlsIndex = TlsAlloc();
    if (((DWORD)-1) == dwTlsIndex) {
        *pIndex = (DWORD)-1;
        goto E_FAIL_EXIT;
    }

    *pIndex = (Aura_UInt32)dwTlsIndex;
    return AURA_NOERROR;

E_FAIL_EXIT:
    return GetLastAuraECode();
}

AURA_API AuraTls_Free(
    /* [in]  */ Aura_UInt32 uIndex)
{
    BOOL bSuccess = FALSE;

    bSuccess = TlsFree((DWORD)uIndex);
    if (!bSuccess) {
        goto E_FAIL_EXIT;
    }
    return AURA_NOERROR;

E_FAIL_EXIT:
    return GetLastAuraECode();
}

AURA_API AuraTls_GetValue(
    /* [in]  */ Aura_UInt32 uIndex,
    /* [out] */ Aura_PVoid * ppValue)
{
    LPVOID pTlsValue = NULL;

    assert(NULL != ppValue);

    pTlsValue = TlsGetValue((DWORD)uIndex);
    if (NULL == pTlsValue) {
        goto E_FAIL_EXIT;
    }

    *ppValue = pTlsValue;
    return AURA_NOERROR;

E_FAIL_EXIT:
    return GetLastAuraECode();
}

AURA_API AuraTls_SetValue(
    /* [in]  */ Aura_UInt32 uIndex,
    /* [in]  */ Aura_PVoid pValue)
{
    BOOL bSuccess = FALSE;

    bSuccess = TlsSetValue((DWORD)uIndex, (LPVOID)pValue);
    if (!bSuccess) {
        goto E_FAIL_EXIT;
    }
    return AURA_NOERROR;

E_FAIL_EXIT:
    return GetLastAuraECode();
}

